home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: LiteFac.cpp 1.1 1996/07/19 00:04:22 Damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // First Light Source Example : Beams Light //
- //--------------------------------------------------------------------//
- // Implementation of the Beams Light Class Factory //
- ////////////////////////////////////////////////////////////////////////
-
- #ifndef __LITEFAC__
- #include "LITEFac.h"
- #endif
-
- #ifndef __COMLITE__
- #include "COMLITE.h"
- #endif
-
- #ifndef __LITEDLL__
- #include "LITEDLL.h"
- #endif
-
-
- // ***** ClassFactory *****
-
- BeamsLightClassFactory::BeamsLightClassFactory() {
- m_cRef=0L; // just created so no reference used
- return;
- }
-
-
- BeamsLightClassFactory::~BeamsLightClassFactory() {
- return;
- }
-
- // IUnknown methods of BeamsLightClassFactory
- STDMETHODIMP BeamsLightClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
- *ppv=NULL;
-
- if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
- *ppv=(LPVOID)this;
-
- if (*ppv!=NULL) {
- ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
-
- STDMETHODIMP_(ULONG) BeamsLightClassFactory::AddRef() {
- return ++m_cRef;
- }
-
-
- STDMETHODIMP_(ULONG) BeamsLightClassFactory::Release() {
- ULONG UnreleaseRef;
-
- UnreleaseRef=--m_cRef;
-
- if (m_cRef == 0)
- delete this; // No reference left, so delete the BeamsLightClassFactory
-
- return UnreleaseRef;
- }
-
- /*
- * BeamsLightClassFactory::CreateInstance
- *
- * Parameters:
- * pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
- * being used in an aggregation.
- * riid REFIID identifying the interface the caller
- * desires to have for the new object.
- * ppvObj LPVOID FAR* in which to store the desired
- * interface pointer for the new object.
- *
- * Return Value:
- * HRESULT NOERROR if successful, otherwise E_NOINTERFACE
- * if we cannot support the requested interface.
- */
-
- STDMETHODIMP BeamsLightClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
- BeamsLight* pObj = NULL;
- HRESULT hr;
-
- *ppvObj = NULL;
- hr = ResultFromScode(E_OUTOFMEMORY);
-
- //Verify that a controlling unknown asks for IUnknown
- if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
- return ResultFromScode(E_NOINTERFACE);
-
- //Create the object passing function to notify on destruction.
- if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExLightsource))
- pObj = new BeamsLight;
- else
- return ResultFromScode(E_NOINTERFACE);
-
- hr=pObj->QueryInterface(IID_I3DExLightsource, ppvObj);
-
- //Kill the object if initial creation failed.
- if (FAILED(hr))
- delete pObj;
- else
- global_count_Obj++;
-
- return hr;
- }
-
-
- /*
- * BeamsLightClassFactory::LockServer
- *
- * Purpose:
- * Increments or decrements the lock count of the DLL. If the
- * lock count goes to zero and there are no objects, the DLL
- * is allowed to unload.
- *
- * Parameters:
- * fLock BOOL specifying whether to increment or
- * decrement the lock count.
- *
- * Return Value:
- * HRESULT NOERROR always.
- */
-
- STDMETHODIMP BeamsLightClassFactory::LockServer(BOOL fLock) {
- if (fLock)
- global_count_Lock++;
- else
- global_count_Lock--;
-
- return NOERROR;
- }
-
-